package com.yanqu.road.server.cmd.activity.washe;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.WasheProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.washe.WasheModule;
import com.yanqu.road.server.manger.activity.washe.WasheMgr;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameErrorCode;
import com.yanqu.road.server.protocol.GameProtocol;

@Cmd(code = GameProtocol.S_WASHE_PING, desc = "")
public class WashePingCmd extends AbstractCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if (player == null) {
            return;
        }
        if (WasheMgr.getWasheConfig() == null) {
            ret = GameErrorCode.E_WASHE_NO_SYSTEM;
            return;
        }
        WasheModule washeModule = player.getModule(WasheModule.class);
        if (washeModule.getWasheUserData() == null) {
            ret = GameErrorCode.E_SYSTEM_NO_OPEN;
            return;
        }

        boolean ping = WasheMgr.ping(player.getUserId());

        WasheProto.WashePingRespMsg.Builder builder = WasheProto.WashePingRespMsg.newBuilder();
        if (ping) {
            builder.setRet(0);
        } else {
            builder.setRet(GameErrorCode.E_WASHE_GAME_END);
        }
        player.sendPacket(ClientProtocol.U_WASHE_PING, builder);
    }

    @Override
    public void sendData(GamePlayer player) {

    }
}
